//
//  main.cpp
//  LearningOops
//
//  Created by Swetha Patnala on 4/14/13.
//  Copyright (c) 2013 Swetha Patnala. All rights reserved.
//

#include <iostream>

#include "File_System_Manager.h"
#include "Inode.h"
#include "File_Operations.h"
#include "Vector.h"

using namespace std;
void Test1();
void Test2();
void Test3();
void Test4();
void Test5();



int main(int argc, const char * argv[])
{
    Test5();
    //Test4();
    
}
void Test1(){
    
    // insert code here...
    std::cout << "Hello, World!\n";
    //CRectangle rect;
    //rect.set_values (3,4);
    //cout << "area: " << rect.area();
    
    
    //File_System_Manager *instance = File_System_Manager::getInstance();
    //File_System_Manager *instance2 = File_System_Manager::getInstance();
    //File_System_Manager *instance3 = File_System_Manager::getInstance();
    
    /*
     
     Inode *newInode[10];
     
     for(int i =0 ; i<10 ;i++){
     
     newInode[i] = new Inode(i , "file");
     
     }
     
     for (int i = 0; i < 10; i++) {
     delete newInode[i];
     }
     
     */
    
    File_System_Manager *file[3];
    
    for(int i =0 ; i<3 ;i++){
        
        file[i] = File_System_Manager::getInstance();
        
    }
    
    delete file[0];
    
    
    
    
}




void Test2(){
    
    
    
    
    File_Operations *newfile = nullptr ;
    
    newfile->fs_create((char*)"firstfile");
    
    newfile->fs_create((char*)"secondfiles");
    
    
    cout << "------------------------------"<<endl;
    
    int fd1 = newfile->fs_open((char*)"firstfile2");
    
    
    cout << "the fd num is " << fd1<<endl;
    int fd2  = newfile->fs_open((char*)"firstfile");
    cout << "the fd num is " << fd2<<endl;
    
    //newfile->fs_close((char*)"firstfile", 2);
    cout << endl;
    newfile->fs_close((char*)"firstfile", fd2);
    
    //newfile->fs_close((char*)"firstfile", 1);
    
    // newfile->fs_delete((char*)"firstfile");
    
    
    newfile->fs_write((char*)"firstfile", 1, (char*)"abcdefgeh", 10);
    
    newfile->fs_write((char*)"firstfile", 1, (char*)"iwererhkj", 10);
    
    
    
    
}

void Test3(){
    
    Vector_Class *vect = new Vector_Class();
    vect->displayVector();
    
    
    
}

void Test4(){
    
    File_System_Manager *file ;
    file = File_System_Manager::getInstance();
    //file->printSuperBlock();
    
    void* buf = NULL;
    File_Operations *newfile = nullptr ;
    
    
    newfile->fs_create((char*)"abc.txt");
    
    newfile->fs_open((char*)"abc.txt");
    
    newfile->fs_write((char*)"abc.txt", 1, (char*)"first sentence", 10);
    
    newfile->fs_write((char*)"abc.txt", 2, (char*)"second line of the file", 10);
    
    cout << "After writing";
    
    newfile->fs_read((char*)"abc.txt", 1, buf, 4096);
    
    
    //file->printDataOftheFile(1);
    
    newfile->fs_close((char*)"abc.txt", 1);
    newfile->fs_close((char*)"abc.txt", 2);
    newfile->fs_delete((char*)"abc.txt");
    
    file->printDataOftheFile(1);
    
}


void Test5(){
    
    File_System_Manager *file ;
    file = File_System_Manager::getInstance();
    
    cout<< "Super block info"  <<endl;
    file->printSuperBlock();
    
    File_Operations *newfile = nullptr ;
    
    newfile->fs_create((char*)"abc.txt");
    
    newfile->fs_write((char*)"abc.txt", 1, (char*)"first sentence", 10);
    
    
    newfile->fs_write((char*)"abc.txt", 1, (char*)"fhello how r u ", 10);
    
    
    newfile->fs_create((char*)"abc2.txt");
    newfile->fs_create((char*)"abc3.txt");
    newfile->fs_create((char*)"abc4.txt");
    newfile->fs_create((char*)"abc5.txt");
    
    
    
    newfile->fs_write((char*)"abc2.txt", 1, (char*)"first sentence", 10);
    
    
    newfile->fs_write((char*)"abc2.txt", 1, (char*)"fhello how r u ", 10);
    
    
    
    newfile->fs_close((char*)"abc.txt", 1);
    
    newfile->fs_delete((char*)"abc.txt");
    cout<< "Super block info"  <<endl;
    file->printSuperBlock();
    
    cout << "Inode Bitmap value " <<endl;
    file->printInodeBitMap();
    
    cout << "Data Bitmap value " <<endl;
    file->printDataBitMap();
    
    newfile->fs_create((char*)"abc6.txt");
    
    cout<< "Super block info"  <<endl;
    file->printSuperBlock();
    
    cout << "Inode Bitmap value " <<endl;
    file->printInodeBitMap();
    
    cout << "Data Bitmap value " <<endl;
    file->printDataBitMap();
    
    newfile->fs_write((char*)"abc2.txt", 1, (char*)"fhello how r u ", 10);
    
    
    
    
}

